//작업현황 정보 수동입력

$(document).ready(function(){
	$("#selectWorkCondition").change(function(){
		if($(this).val()==="bad"){
			$("#wiptr1 td:eq(3)").after("<td class='addMenu'>불량정보</td>");
			$("#wiptr2 td:eq(3)").after("<td class='addMenu'><select id='selecterrorinfo'><option>세부불량정보</option>"
					+"<option value='배추불량'>배추불량</option>"
					+"<option value='소금불량'>소금불량</option>"
					+"<option value='양념불량'>양념불량</option>"
					+"<option value='포장훼손'>포장훼손</option>"
					+"</select></td>");
			
		}
		else if($(this).val()!=="bad"){
			$(".addMenu").remove();
		}
	});
	$("#registerWorkBtn").click(function(){
		var command="";
		var stationName=$("#wiptr2").find(".stationSatusTableSatus").text();
		var a=$("#selectWorkCondition").val();
		console.log(stationName);
		//불량발생 선택
		if(a==="bad"){
			var b=$("#selecterrorinfo").val();
			if(b!==""){
				command="command=play&station_name="+stationName
				+"&condition_name="+b;
			}
			else{
				alert("불량유형을 선택해 주세요.");
				$(".addMenu").remove();
			}
		}
		else{
			command="command=play&station_name="+stationName
			+"&condition_name="+a;
		};
		$.ajax({
			type : "POST",
			url : "kimchi.do",
			data : command,
			dataType:"json",
			success:function(jsonData){
				//세부공정현황테이블
				$("#waitCount").html(jsonData.info.count.waitCount);
				$("#completeCount").html(jsonData.info.count.completeCount);
				$("#errorCount").html(jsonData.info.count.errorCount);
				$("#statusTotal").html(jsonData.info.count.totalCount);
				$.livechart(jsonData.info.count.totalCount,"실시간 작업 현황");
				//불량상세정보테이블
				var errorList=jsonData.info.errorCount;
				var error="";
				$.each(errorList,function(i,value){
					error+="<tr><td>"+value.condition_name+"</td>";
					error+="<td>"+value.error_quantity+"</td></tr>";
				});
				$("#errordetail").html(error);
				//공정내세부사항
				var detailInfo=jsonData.info.productList;
				var infotext="";
				$.each(detailInfo,function(i,value){
					infotext+=" "+value.lot_no+"     ";
					infotext+=value.station_name+"     ";
					infotext+=value.condition_name+"\n";
				});
				$("#textArea").html(infotext);
			}
		});
		$.ajax({
			type : "POST",
			url : "kimchi.do",
			data : "command=getWorkOrder",
			dataType:"json",
			success:function(jsonData){
				$(".orderNo").html(jsonData.vo.workorder_no);
				$("#startTime").html(jsonData.vo.workorder_date);
				$("#orderQuantinity").html(jsonData.vo.workorder_quantity);
				$("#completeQuantinity").html(jsonData.vo.complete_quantity);
				$("#statusProcess").html(jsonData.vo.workorder_percent);
			}
		});
	});
});